<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('库存盘点列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="col-sm-3">
                                <label>[[#{warehouse}]]：</label>
                                <div class="input-group">
                                    <input name="warehouseId" class="form-control" type="hidden">
                                    <input id="suggest-warehouse" class="form-control" type="text">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <label>[[#{stocktakingNumber}]]：</label>
                                <input type="text" name="inventoryListNumber"/>
                            </li>
                            <li>
                                <label>[[#{documentDate}]]：</label>
                                <input type="text" class="time-input" id="beginDocumentDate" th:placeholder="#{beginTime}" name="params[beginDocumentDate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endDocumentDate" th:placeholder="#{endTime}" name="params[endDocumentDate]" />
                            </li>
                            <li>
                                <label>[[#{status}]]：</label>
                                <select name="status" th:with="type=${@dict.getType('jt_inventory_status')}">
                                    <option value="">[[#{all}]]</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>[[#{reviewer}]]：</label>
                                <input type="text" name="reviewer"/>
                            </li>
                            <li>
                                <label>[[#{validationTime}]]：</label>
                                <input type="text" class="time-input" id="beginValidationTime" th:placeholder="#{beginTime}" name="params[beginValidationTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endValidationTime" th:placeholder="#{endTime}" name="params[endValidationTime]" />
                            </li>
                            <li>
                                <label>[[#{createTime}]]：</label>
                                <input type="text" class="time-input" id="beginCreateTime" th:placeholder="#{beginTime}" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endCreateTime" th:placeholder="#{endTime}" name="params[endCreateTime]" />
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;[[#{search}]]</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;[[#{reset}]]</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="business:stocktaking:remove">
                    <i class="fa fa-remove"></i> [[#{delete}]]
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="business:stocktaking:export">
                    <i class="fa fa-download"></i> [[#{export}]]
                </a>

                <a class="btn btn-info" onclick="$.table.importExcel();" shiro:hasPermission="business:product:edit">
                    <i class="fa fa-download"></i> [[#{import}]]
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-suggest-js" />
    <script th:inline="javascript">
        var removeFlag = [[${@permission.hasPermi('business:stocktaking:remove')}]];
        var statusDatas = [[${@dict.getType('jt_inventory_status')}]];
        var prefix = ctx + "business/stocktaking";

        $(function() {
            var options = {
                url: prefix + "/list",
                viewUrl: prefix + "/view/{id}",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: i18n('stocktaking'),
                columns: [{
                    checkbox: true
                },
                {
                    field: 'stocktakingId',
                    title: '库存盘点id',
                    visible: false
                },
                {
                    field: 'warehouseName',
                    title: i18n('warehouse')
                },
                {
                    field: 'inventoryListNumber',
                    title: i18n('stocktakingNumber'),
                    formatter: function (value, row, index) {
                        return value +'<a href="javascript:void(0)" onclick="$.operate.view(\'' + row.stocktakingId + '\')"><span class="badge badge-info">详</span></a>';
                    }
                },
                {
                    field: 'documentDate',
                    title: i18n('documentDate')
                },
                {
                    field: 'status',
                    title: i18n('status'),
                    sortable: true,
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'preTotalQty',
                    title: i18n('preMarketTotal')//'盘点前总数量'
                },
                {
                    field: 'postTotalQty',
                    title: i18n('afterHoursTotal')//'盘点后总数量'
                },
                {
                    field: 'reviewer',
                    title: i18n('reviewer')
                },
                {
                    field: 'validationTime',
                    title: i18n('validationTime'),
                    sortable: true
                },
                {
                    field: 'remark',
                    title: i18n('remark')
                },
                {
                    field: 'createBy',
                    title: i18n('createBy')
                },
                {
                    field: 'createTime',
                    title: i18n('createTime'),
                    sortable: true
                },
                {
                    title: i18n('operate'),
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.stocktakingId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        var warehouseSuggest = $("#suggest-warehouse").bsSuggest({
            url: ctx + "business/warehouse/select/list",
            idField: "warehouseId",
            keyField: "warehouseName",
            clearable: true,
            ignorecase: true,
            hideOnSelect: true,
            effectiveFields: ["warehouseId", "warehouseName"],
            effectiveFieldsAlias: {warehouseId: "仓库ID", warehouseName: "仓库"},
        }).on('onSetSelectValue', function (e, selectedData, selectedRawData) {
            console.log('onSetSelectValue: ', selectedData);

            $("input[name='warehouseId']").val(selectedRawData.warehouseId);
        }).on('onUnsetSelectValue', function (e) {
            //console.log("onUnsetSelectValue=="+e);
            $("input[name='warehouseId']").val("");
        });


        //确认生效
        function validation(){
            table.set();
            var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning(i18n('pleaseSelectAtLeastOne'));
                return;
            }
            $.modal.confirm("确认【确认生效】选中的" + rows.length + "条数据吗?", function() {
                var url = prefix + "/validation";
                var data = { "ids": rows.join() };
                $.operate.submit(url, "post", "json", data);
            });
        }
    </script>
     <script th:inline="javascript">
         var ROOT = [[${#servletContext.contextPath}]];
         var LANG_COUNTRY = [[${#locale.language+'_'+#locale.country}]];

         //初始化i18n
         $.i18n.properties({
             path: ROOT + '/i18n/',//这里表示访问路径
             name: 'messages',//文件名开头
             language: LANG_COUNTRY,//文件名语言 例如en_US
             mode: 'map'//默认值
         });

         //i18n函数
         function i18n(msgKey) {
             try {
                 return $.i18n.prop(msgKey);
             } catch (e) {
                 return msgKey;
             }
         }
     </script>
</body>


<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"/>
            <div class="mt10 pt5">
                导入库存盘点信息<br/>
                仓库：
                <select name="warehouseId" required>
                    <option th:each="warehouseVo : ${warehouseVoList}" th:text="${warehouseVo.warehouseName}" th:value="${warehouseVo.warehouseId}"></option>
                </select>
                <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                注意：1、点击了"导入"数据就会导入到系统,立即生效，请勿重复操作。
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>